package com.example.yls.cnbetaapp.util;

import android.renderscript.ScriptGroup;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class HttpUrlConnectionUtil {
    public  String getObjJson(String url){
        try {
            URL uri = new URL(url);
            HttpURLConnection conn =(HttpURLConnection)uri.openConnection();
            conn.setConnectTimeout(6000);
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setRequestMethod("GET");
            conn.connect();
            InputStream in = conn.getInputStream();
            ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
            byte[] bytes = new byte[1024];
            int ch;
            while((ch = in.read(bytes)) != -1){
                byteStream.write(bytes,0,ch);
            }
           String objJson = new String(byteStream.toByteArray(),"utf-8");
           return objJson;

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
